package com.smile.ye.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class FieldMetaObjectHandler implements MetaObjectHandler {
    /**新增时间**/
    private final String TIME_CREATE = "createdAt";
    /**更新时间**/
    private final String TIME_UPDATE = "updatedAt";

    /**
     * 新增默认填充器
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, TIME_CREATE, LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, TIME_UPDATE, LocalDateTime.class, LocalDateTime.now());
    }


    /**
     * 更新默认填充器
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        //最后更新时间
        this.strictInsertFill(metaObject, TIME_UPDATE, LocalDateTime.class, LocalDateTime.now());
    }
}